package com.ope.web.controller.handlecontrol;

import com.ope.common.core.controller.BaseController;
import com.ope.web.controller.chainresponsibility.TopicDataParser;
import com.ope.web.model.DTO.ProcessMointorRequestBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.concurrent.*;

/**
 * 测试运维保障
 * 
 * @author gnrx
 */
@Controller
@RequestMapping("/handle")
@Slf4j
public class HandleController extends BaseController {

    /**
     * 队列满了 使用主线程处理
     */
    private static final ExecutorService THREAD_POOL_DEVICE_DATA = new ThreadPoolExecutor(16, 32,
            0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1000),
            Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());


    @Autowired
    private TopicDataParser topicDataParser;

    @PostMapping("/test")
    @ResponseBody
    public void list() {
        THREAD_POOL_DEVICE_DATA.submit(() -> {
            try {
                ProcessMointorRequestBody processMointorRequestBody = new ProcessMointorRequestBody();

                String hostname = "10.10.12.114";
                String username = "root";
                String password = "SPrixin.2024";
                String processToCheck = "sppp";
                String startCommand = " /home/sprixin/sprixinSoft/jdk/bin/java -Dfile.encoding=utf-8"
                        + " -jar  -Dloader.path=/home/sprixin/sprixinWeb/web/jar/rxpg-sppp"
                        + "  /home/sprixin/sprixinWeb/web/jar/rxpg-sppp.xjar "
                        + "--spring.config.location=/home/sprixin/sprixinWeb/web/config/bootstrap-sppp.yml";
                processMointorRequestBody.setHostname(hostname);
                processMointorRequestBody.setUsername(username);
                        processMointorRequestBody.setPassword(password);
                processMointorRequestBody.setProcessName(processToCheck);
                processMointorRequestBody.setBatsh(startCommand);
                topicDataParser.dataReporting(processMointorRequestBody);
            } catch (Exception e) {
                log.error("运维保障程序出现异常", e);
            }
        });
    }


}
